﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Xml;

using iTextSharp.text.pdf;

namespace iPdf
{
    public enum WorkStatus
    {
        Idle = 0,
        Busy = 1,
        TaskImported = 2
    }

    public enum JumpDirection
    {
        Previous = 0,
        Next = 1,
        First = 2,
        Last = 3
    }

    public enum PrintingPermissionId
    {
        None = 0,
        LowResolution = 1,
        HighResolution = 2
    }

    public enum EditingPermissionId
    {
        None = 0,
        ManipulatePages = 1,
        FillingInFormFieldsAndSigning = 2,
        FillingInFormFieldsAndSigningAndCommenting = 3,
        AllExceptPageExtraction = 4
    }

    public enum SecurityLevelId
    {
        None = 0,
        PasswordSecurity = 1,
        CertificateSecurity = 2
    }

    class SecurityLevel
    {
        public SecurityLevelId Id;
        public string Text;
        
        public SecurityLevel(SecurityLevelId id, string text)
        {
            Id = id;
            Text = text;
        }

        public override string ToString()
        {
            return Text;
        }
    }

    class Permission
    {
        public bool AllowCopyContent;
        public bool AllowScreenReader;
        public PrintingPermissionId PrintingPermission;
        public EditingPermissionId EditingPermission;

        public static readonly Permission AllAllowedPermission;
        public static readonly Permission AllNotAllowedPermission;

        static Permission()
        {
            AllAllowedPermission = new Permission();
            AllAllowedPermission.AllowCopyContent = true;
            AllAllowedPermission.AllowScreenReader = true;
            AllAllowedPermission.PrintingPermission = PrintingPermissionId.HighResolution;
            AllAllowedPermission.EditingPermission = EditingPermissionId.AllExceptPageExtraction;

            AllNotAllowedPermission = new Permission();
            AllNotAllowedPermission.AllowCopyContent = false;
            AllNotAllowedPermission.AllowScreenReader = false;
            AllNotAllowedPermission.PrintingPermission = PrintingPermissionId.None;
            AllNotAllowedPermission.EditingPermission = EditingPermissionId.None;
        }

        public int Permissions
        {
            get
            {
                int permissions = 0;
                if (AllowCopyContent)
                {
                    permissions |= PdfWriter.ALLOW_COPY;
                }

                if (AllowScreenReader)
                {
                    permissions |= PdfWriter.ALLOW_SCREENREADERS;
                }

                switch (PrintingPermission)
                {
                    case PrintingPermissionId.HighResolution:
                        permissions |= PdfWriter.ALLOW_PRINTING;
                        break;

                    case PrintingPermissionId.LowResolution:
                        permissions |= PdfWriter.ALLOW_DEGRADED_PRINTING;
                        break;
                }

                switch (EditingPermission)
                {
                    case EditingPermissionId.ManipulatePages:
                        permissions |= PdfWriter.AllowAssembly;
                        break;

                    case EditingPermissionId.FillingInFormFieldsAndSigning:
                        permissions |= PdfWriter.AllowAssembly | PdfWriter.AllowFillIn;
                        break;

                    case EditingPermissionId.FillingInFormFieldsAndSigningAndCommenting:
                        permissions |= PdfWriter.AllowAssembly | PdfWriter.AllowFillIn |
                                                    PdfWriter.AllowModifyAnnotations;
                        break;

                    case EditingPermissionId.AllExceptPageExtraction:
                        permissions |= PdfWriter.AllowAssembly | PdfWriter.AllowFillIn |
                                                    PdfWriter.AllowModifyAnnotations |
                                                    PdfWriter.AllowModifyContents;
                        break;
                }

                return permissions;
            }
        }
    }

    public struct BalloonTip
    {
        public string Title;
        public string Text;
        public int Timeout;
        public ToolTipIcon Icon;
    }

    public enum CertifyLevelID
    {
        NotCertified = PdfSignatureAppearance.NOT_CERTIFIED,
        NoChangesAllowed = PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED,
        FormFilling = PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED,
        FormFillingAndAnnotations = PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
    }

    class CertifyLevel
    {
        public CertifyLevelID Id;
        string Description;

        static int CurrentId;

        public CertifyLevel(string description)
        {
            Id = (CertifyLevelID) CurrentId;
            ++CurrentId;
            Description = CurrentId.ToString() + ". " + description;
        }

        public override string ToString()
        {
            return Description;
        }
    }

    public enum CertificateSource
    {
        System,
        File
    }


    class BookmarkNode
    {
        private Hashtable map ;

        public Hashtable Map
        {
            get
            {
                return map;
            }
        }

        public bool IsTopLevelNode
        {
            get
            {
                return Parent == null;
            }
        }

        public int Level
        {
            get
            {
                return map["Level"] == null? 0 : (int)map["Level"];
            }
        }

        public Hashtable Parent
        {
            get
            {
                return (Hashtable)map["Parent"];
            }
        }

        public BookmarkNode ParentNode
        {
            get
            {
                return new BookmarkNode(Parent);
            }
        }


        public void AddKid(BookmarkNode node)
        {
            AddKid(node.map);
        }

        public void AddKid(Hashtable kid)
        {
            if (map["Kids"] == null)
            {
                map["Kids"] = new ArrayList();
            }

            ArrayList kids = (ArrayList)map["Kids"];
            kids.Add(kid);
            kid["Parent"] = map;
        }

        public BookmarkNode()
        {
            map = new Hashtable();
        }

        public BookmarkNode(Hashtable node)
        {
            this.map = node;
        }
    }

    public enum FileStatus
    {
        Normal,
        InUse,
        NotExist
    }

    public enum OfficeDocumentType
    {
        WordDocument = 0,
        ExcelSheet,
        PowerPointPresentation
    }

}
